package com.qf.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaojian
 */
@RestController
@RefreshScope  //刷新配置信息
@RequestMapping("/provider")
public class TestProviderController {

    @Value("${text}")
    private String name;

    //给资源取一个名字
    @SentinelResource(value = "/ytt",blockHandler = "blockException",fallback = "fallback")
    @RequestMapping("/hello")
    public String test(String age) {
//        try {
//            Thread.sleep(1500);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(age);
        return "欢迎来到千锋教育, 北科校区学习java编程!"+name+age;
    }
    public String blockException(String age, BlockException e) {
        e.printStackTrace();
        return "限流了!!!";

    }
    public String fallback(String age, Throwable e) {
        e.printStackTrace();
        return "出现异常了!!!";

    }
}
